/**************************************
Syntax for additional analyses in 
Online Appendix C
***************************************/

clear 
cd "C:\Users\Joshua\OneDrive\Documents\Work - Finished\BJPS - Comp Explanations\Dataverse"
use "exp2_cleaned.dta"
set more off

/**************************
Figure OC2
***************************/

histogram therm_pre, by(copartisan, total title("Distribution of Initial Politician Impressions") note("")) xtitle("Thermometer (Pre-Test)") ///
		discrete scheme(plotplain)
		
graph save "figure_oc2", replace
graph export "figure_oc2.png", replace


/**********************
Alternative Specifications
************************/
recode treat_expl (1 = 1 "No Justification") (2 = 2 "Justification") (3 4 = 3 "Just. w/Counter"), gen(treat1)

label def expj 1 "No Justification" 2 "Justification" 3 "HC Counter" 4 "LC Counter" 
label values treat_expl expj

summ therm_diff
gen therm_diff_01 = (therm_diff - r(min))/(r(max)-r(min))

******Difference Score: Table OC1

****Models
eststo clear
*Figure 1
eststo: regress therm_diff_01 ib2.treat1 i.treat_party therm_pre01

*Figure 2
eststo: regress therm_diff_01 ib2.treat_expl i.treat_party therm_pre01
		margins, dydx(3.treat_expl 4.treat_expl) post coeflegend
		test _b[3.treat_expl] = _b[4.treat_expl]
		lincom _b[3.treat_expl] - _b[4.treat_expl]

*Figure 3
eststo: regress therm_diff_01 ib2.treat_expl##i.copartisan therm_pre01
		margins,  dydx(3.treat_expl 4.treat_expl) at(copartisan==(1 2))  post coeflegend
		*co-partisans*
		lincom _b[3.treat_expl:1bn._at] - _b[4.treat_expl:1bn._at]
		test _b[3.treat_expl:1bn._at] = _b[4.treat_expl:1bn._at]
		*opposing*
		lincom _b[3.treat_expl:2._at] - _b[4.treat_expl:2._at]
		test _b[3.treat_expl:2._at] =_b[4.treat_expl:2._at]
		*diff in diff*
		mlincom (1-3) - (2-4), all
		
	
esttab using table_oc1_alt.rtf, replace onecell  nobaselevels ///
	b(2) se ar2 star(+ 0.1 * 0.05 ** 0.01) ///
	mtitles("Figure 1" "Figure 2" "Figure 3") ///
	title("{\b Table OC1}: Difference Score") label ///
	addnotes("Baseline Categories: Justification (all models); Democratic Legislator (model 2); Co-Partisan legislator (model 3)")
	
	
	
regress therm_diff_01 ib2.treat_expl##i.copartisan therm_pre01
margins, dydx(3.treat_expl 4.treat_expl) at(copartisan = (1 2)) coeflegend post 

*Within
*Co-Partisans
	*HC - LC
	test _b[3.treat_expl:1bn._at] = _b[4.treat_expl:1bn._at]
	lincomest _b[3.treat_expl:1bn._at] - _b[4.treat_expl:1bn._at]

*Opposing Partisans
	*HC - LC
	regress therm_diff_01 ib2.treat_expl##i.copartisan therm_pre01
	margins, dydx(3.treat_expl 4.treat_expl) at(copartisan = (1 2)) coeflegend post 

	test _b[3.treat_expl:2._at] = _b[4.treat_expl:2._at]
	lincomest _b[3.treat_expl:2._at] - _b[4.treat_expl:2._at]

	
*Between
regress therm_diff_01 ib2.treat_expl##i.copartisan therm_pre01
margins, dydx(3.treat_expl 4.treat_expl) at(copartisan = (1 2)) coeflegend post 

*(Co-Partisan: HC-LC) - (Opposing Partisan: HC-LC)
mlincom (1-3) - (2-4), stats(all)
	
******Categorical DV, Table OC2/3
tab therm_change

*Combined explanations
eststo clear
eststo: mlogit therm_change ib2.treat_expl i.copartisan, base(2)

*Table
esttab using "table_oc2.rtf", ///
	replace onecell se star(+ 0.1 * 0.05 ** 0.01) ///
	nobaselevels b(2) ///
	unstack label pr2 ///
	title("{\b Table OC2}: Multinomial Logit Models, Experiment 2") ///
	addnotes("Reference category is 'No Change in Thermometer'")

*Figure
margins treat_expl, predict(outcome(1))
margins treat_expl, predict(outcome(2))
margins treat_expl, predict(outcome(3))


*****Interaction
eststo clear
eststo: mlogit therm_change ib2.treat_expl##i.copartisan, base(2)

esttab using "table_oc3.rtf", ///
	replace onecell se star(+ 0.1 * 0.05 ** 0.01) ///
	nobaselevels b(2) ///
	unstack label pr2 ///
	title("{\b Table OC3}: Multinomial Logit Models: Interaction, Experiment 2") ///
	addnotes("Reference category is 'No Change in Thermometer'")

	
forval i = 1/3 {
	margins, dydx(treat_expl) at(copartisan==(1 2)) predict(outcome(`i')) saving(inter_probs_`i', replace)
}	


/**********************
Additional Variables: Table OC5
************************/
**All
foreach var in policy posmot negmot   {
	mean `var', over(treat_expl)
}

**Co-Partisans
foreach var in policy posmot negmot   {
	mean `var' if copartisan_1 == 1, over(treat_expl)
}

**Opposing
foreach var in policy posmot negmot   {
	mean `var' if copartisan_1 == 0, over(treat_expl)
}

	
	
	
	
	
	
	
	
	
	
	
	
